package Sort.面试.宁波银行;

import java.util.Scanner;

/**
 * 字符串反转 i like beijing.  反转成 beijing. like i
 */
public class StringReverse {

    public static String reverseString(String str){
        if(str == null || str.equals("")){
            return str;
        }
        String[] strArr = str.split(" ");
        if(strArr == null || strArr.length == 0){
            return str;
        }
        String res = strArr[strArr.length - 1];

        for (int i = strArr.length - 2; i > 0; i--) {
            res += " " + strArr[i];
        }
        return res;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        System.out.println("请输入数组大小");
        int length = in.nextInt();

        String str = "";
        for (int i = 1; i <= length; i++) {
            System.out.println("请输入第"+ i + "个字符串");
            str += " " + in.next();
        }
        System.out.println(str);

        str.replaceFirst(" ", "");

        System.out.println(reverseString(str));
    }
}
